The TO_DATE
and TO_TIMESTAMP
functions are converting char of CHAR
, VARCHAR2
,
NCHAR
, or NVARCHAR2
datatype to respectively a value of DATE
or TIMESTAMP
datatype.
Without providing the format of the input char, TO_DATE
will consider the provided char is compliant with the default date format.
Relying on a default configuration is a source of error because it creates a dependency between the code and the configuration of the ORACLE server
where this code is deployed.
According to the Oracle’s documentation "the default date format is determined implicitly by the NLS_TERRITORY initialization parameter or can be
set explicitly by the NLS_DATE_FORMAT parameter.". It means the behaviour of the TO_DATE
function will certainly not be the expected one
if the configuration of the ORACLE server is changing.
Noncompliant code example
SELECT TO_DATE( 'January 15, 2018, 11:00 A.M.')
FROM DUAL;
Compliant solution
SELECT TO_DATE( 'January 15, 2018, 11:00 A.M.', 'Month dd, YYYY, HH:MI A.M.')
FROM DUAL;